//
// Created by xm on 2024/5/22.
//

#include "test05.h"
#include "iostream"

using namespace std;



void mySwapInt(int &a, int &b){
    int tmp = a;
    a = b;
    b = tmp;
}

void mySwapDouble(double &a, double &b){
    double tmp = a;
    a = b;
    b = tmp;
}

template<class T>
static void mySwap(T &a, T &b){
    T tmp = a;
    a = b;
    b = tmp;
}

static void demo1()
{
    cout << "------ demo1 ------" << endl;

    int a1 = 10;
    int b1 = 20;
    mySwapInt(a1, b1);
    cout << "a1="<< a1 << "  b1=" << b1 << endl;

    int a2 = 10;
    int b2 = 20;
    mySwap<int>(a2, b2);
    cout << "a2="<< a2 << "  b2=" << b2 << endl;



}

// 排序
template<class T>
static void d2_Swap(T &a, T &b){
    T tmp = a;
    a = b;
    b = tmp;
}

template<class T>
static void d2_Sort(T arr[], int len)
{
    for (int i = 0; i < len-1; ++i) {
        int max = i;
        for (int j = i+1; j < len; ++j) {
            if(arr[max] < arr[j]){
                max = j;
            }
        }
        if(max != i){
            d2_Swap(arr[max], arr[i]);
        }
    }
}

template<class T>
void d2_print(T arr[], int len){
    for (int i = 0; i < len; ++i) {
        cout << arr[i] << " ";
    }
    cout << endl;
}

// m.printMarker()
static void demo2()
{
    cout << "------ demo2 ------" << endl;

    char  arr1[] = "hello world";
    int  len1 = sizeof(arr1) / sizeof(char ) -1;
    d2_Sort(arr1, len1);
    d2_print(arr1, len1);

    int  arr2[] = {3, 8, 4,2,1,9};
    int  len2 = sizeof(arr2) / sizeof(int);

    d2_Sort(arr2, len2);
    d2_print(arr2, len2);

    // 模板类模版的继承
    // 类模板的成员函数类外实现
    // 类内实现、类外实现
    // 掰开揉碎。浅水区、自驱力、
    // About Us
    // Video Tutorial

}

    // Helmet Smart HUD
    // Accessories
    // Support

// 类模版
static void demo3()
{
    cout << "------ demo3 ------" << endl;

    // demo3
    // demo3
    // demo3 整个类，模板化
}


void  test05()
{
    cout << "=======【test05】=======" << endl;
//    demo1();
    demo2();
    //


}